import axios from '../../../utils/request';
import { fromJS } from 'immutable';
import * as constants from './constants';

// 保存store
 
const saveTopicsIndo = (topicList) => ({
	type: constants.GET_TOPICS,
	data: fromJS(topicList),
});


// 执行异步请求
export const getTopics = (params) => {
	return (dispatch) => {
		axios.get('/topics', {params: params}).then((res) => {
			const data = res.data;
			dispatch(saveTopicsIndo(data.data));
		}).catch(() => {
			console.log('error');
		})
	}
};